﻿using CSScriptLibrary;
using LEDControllerTools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.CodeDom.Compiler;

namespace RunController
{
    class Program
    {
        public interface IScript
        {
            void Hello(string greeting);
        }

        static void Main(string[] args)
        {

            var PrintSum = CSScript.LoadMethod(
                                    @"public static void PrintSum(int a, int b)
                                  {
                                      Console.WriteLine((a+b));
                                  }")
                                      .GetStaticMethod();
            PrintSum(1, 2);

            var Test = CSScript.LoadMethod(
            @"public static void Test()
                          {
                             dynamic d = ""123"";
                             Console.WriteLine(d.ToString() + "": "" +d.Length);
                          }")
             .GetStaticMethod();
            Test();

//            var test = CSScript.LoadMethod(
//                @"        public void Run()
//        {
//            var cont = Controller.GetInstance<LEDControllerTools.Commands.Rs232CommandFactory>();
//            cont.BatteryUpdate += cont_BatteryUpdate;
//            cont[""A1""].On();
//        }");
           // test.GetStaticMethod().Invoke();
            //Run();

        }

        public void Run()
        {
            var cont = Controller.GetInstance<LEDControllerTools.Commands.Rs232CommandFactory>();
            cont.BatteryUpdate += cont_BatteryUpdate;
            cont["A1"].On();
        }

        static void cont_BatteryUpdate(float battery)
        {
            throw new NotImplementedException();
        }
    }
}
